package tests;

import gameComponents.Player;
import gamePieces.Pawn;

import java.awt.Point;
import java.util.ArrayList;

import junit.framework.TestCase;

/**
 * 
 */

/**
 * @author SELMAN
 *
 */
public class PawnTest extends TestCase {

	Player pl = new Player(1);
	Pawn p = new Pawn(0,0,pl);
	/**
	 * @param name
	 */
	public PawnTest(String name) {
		super(name);
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for {@link Pawn#checkIfLegal(int, int)}.
	 * @author Selman Selman
	 */
	public final void testCheckIfLegal() {
		//check if checkIfLegal would return true if pawn moves one forward
		assertTrue(p.checkIfLegal(0,1));
		//check if checkIfLegal would return true if pawn moves 2 forward
		assertTrue(p.checkIfLegal(0, 2));
		//check if checkIfLegal would return true if pawn wants to eat diagonally 
		assertTrue(p.checkIfLegal(1, 1));	
		//checks if checkIfLegal would return false if pawn tries to move 3 forward
		assertFalse(p.checkIfLegal(0, 3));
		//checks if checkIfLegal would return false if pawn tries to move 2 steps diagonally
		assertFalse(p.checkIfLegal(2, 2));
	}

	/**
	 * Test method for {@link Pawn#move(int, int)}.
	 * @author Selman Selman
	 */
	public final void testMove() {
		//checks if pawn will move 2 forward at the start
		p.move(0,2);
		assertEquals(p.getX(),0);
		assertEquals(p.getY(), 2);
		//new x and y coordinates are 0 and 1 respectively 
		//check if pawn will move 1 forward
		p.move(0,3); // knight should not move
		assertEquals(p.getX(),0);
		assertEquals(p.getY(),3);
		
		//checks if pawn will move 1 diagonally
		p.move(1,4);
		assertEquals(p.getX(),1);
		assertEquals(p.getY(),4);
		//move pawn out of boundaries
		p.move(9,9); //pawn should not move
		assertEquals(p.getX(),1);
		assertEquals(p.getY(),4);
	}

	/**
	 * Test method for {@link Pawn#hasMoved()}.
	 * @author Selman Selman
	 */
	public final void testHasMoved() {
		assertFalse(p.hasMoved()); //checks if has moved returns false if pawn has not moved yet
		p.move(0,1); //move pawn
		assertTrue(p.hasMoved()); //should be true
	}

	/**
	 * Test method for {@link Piece#getX()}.
	 * @author Selman Selman
	 */
	public final void testGetX() {
		//since pawn is created initially at (0,0)
		//getX() should return 0
		assertEquals(p.getX(),0);
	}

	/**
	 * Test method for {@link Piece#getY()}.
	 * @author Selman Selman
	 */
	public final void testGetY() {
		//since pawn is created initially at (0,0)
		//gety() should return 0
		assertEquals(p.getY(),0);
	}

	/**
	 * Test method for {@link Piece#setX(int)}.
	 * @author Selman Selman
	 */
	public final void testSetX() {
		p.setX(1); // set x coordinate to 1
		//check that x is now 1
		assertEquals(p.getX(),1);
	}

	/**
	 * Test method for {@link Piece#getOwnership()}.
	 * @author Selman Selman
	 */
	public final void testGetOwnership() {
		//get Ownership should return object p
		assertEquals(p.getOwnership(),pl);
	}

	/**
	 * Test method for {@link Piece#setY(int)}.
	 * @author Selman Selman
	 */
	public final void testSetY() {
		p.setY(1); // set y coordinate to 1
		//check that y is now 1
		assertEquals(p.getY(),1);
	}

	/**
	 * Test method for {@link Piece#getMoves()}.
	 * @author Selman Selman
	 */
	public final void testGetMoves() {
		p.possibleMoves();
		ArrayList<Point> pi = p.getMoves(); //get possible moves
		//makes sure that it contains all possible moves
		assertTrue(pi.contains(new Point(0,1)));
		assertTrue(pi.contains(new Point(0,2)));
		assertTrue(pi.contains(new Point(1,1)));
		
		//makes sure it does not contain a wrong possible move
		assertFalse(pi.contains(new Point(3,3)));
		
	}

}
